package com.xxxy.df.baseui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class B1Activity extends AppCompatActivity {
    Button btnFind,btnShow,btnReturn ;
    boolean res,flag; // res:接收的答案值, flag:是否查看过答案
    TextView tvAnswer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_b1);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        init(); // 初始化界面组件
    }

    private void init(){
        // 接收从A1Activity传递过来的数据
        Intent intent = getIntent();
        if(intent != null){
            res = intent.getBooleanExtra("answer", false);
            Toast.makeText(B1Activity.this,res+"",Toast.LENGTH_SHORT).show();
        }

        // 绑定界面组件
        btnReturn = findViewById(R.id.btn_return);
        btnShow = findViewById(R.id.btn_show);

        // 返回按钮点击事件
        btnReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent data = new Intent();
                data.putExtra("flag",flag); // 返回查看答案标记
                setResult(RESULT_OK,data);
                finish(); // 结束当前Activity
            }
        });

        tvAnswer = findViewById(R.id.tv_answer);

        // 显示答案按钮点击事件
        btnShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvAnswer.setText(res+"，正确答案是9"); // 显示答案
                flag = true; // 标记已查看答案
            }
        });
    }
}
